<template>
  <el-container style="height: 100vh">
    <el-header
      style="background-color: rgb(67, 74, 80); line-height: 60px; color: #fff"
    >
      <el-row :gutter="20">
        <el-col :span="16" class="top">
          <i class="el-icon-goods logo"></i>
          vantshop后台管理系统
        </el-col>
        <el-col :span="8" style="text-align: right" class="top">
          <!-- <i class="el-icon-s-custom"></i>
             -->
          <el-avatar
            src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
          ></el-avatar>
          {{ userInfo.username }}
          <el-button type="text" @click="logout">退出</el-button>
        </el-col>
      </el-row>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu
          style="height: 100%"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          router
        >
          <template v-for="item in menu">
            <el-submenu
              :index="item.path"
              v-if="item.children"
              :key="item.path"
            >
              <template #title
                ><i :class="item.icon"></i>{{ item.text }}</template
              >
              <el-menu-item
                :index="'/manage' + item.path + it.path"
                v-for="it in item.children"
                :key="it.path"
                >{{ it.text }}</el-menu-item
              >
            </el-submenu>
            <el-menu-item :key="item.path" :index="'/manage' + item.path" v-else
              ><i :class="item.icon"></i>{{ item.text }}</el-menu-item
            >
          </template>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  name: "Manage",
  data() {
    return {
      menu: [
        {
          path: "/home",
          text: "首页",
          icon: "el-icon-s-home",
        },
        {
          path: "/goods",
          text: "商品管理",
          icon: "el-icon-s-order",
          children: [
            {
              path: "/list",
              text: "商品列表",
            },
            {
              path: "/add",
              text: "添加商品",
            },
          ],
        },
        {
          path: "/user",
          text: "用户管理",
          icon: "el-icon-user",
          children: [
            {
              path: "/list",
              text: "用户列表",
            },
            {
              path: "/add",
              text: "添加用户",
            },
          ],
        },
        {
          path: "/order",
          text: "订单管理",
          icon: "el-icon-s-operation",
          children: [
            { path: "/list", text: "订单列表" },
            {
              path: "/add",
              text: "添加订单",
            },
          ],
        },
      ],
    };
  },
  computed: {
    //获取用户信息
    userInfo() {
      return this.$store.state.user.userInfo;
    },
  },
  methods: {
    logout() {
      this.$store.commit("user/logout");
      this.$router.push("/login");
    },
  },
};
</script>
<style>
.logo {
  font-size: 36px;
  vertical-align: middle;
  margin-right: 10px;
}

.top span,i {
  vertical-align: middle;
}
</style>
